# -*- coding: utf-8 -*-

import gradio as gr, tempfile, os
from src import extract, preprocess, predict

def pdf_to_radar(pdf_file):
    with tempfile.TemporaryDirectory() as tmp:
        tmp_pdf = os.path.join(tmp, "tmp.pdf")
        with open(tmp_pdf, "wb") as f:
            f.write(pdf_file)
        extract.run(tmp)
        preprocess.run(tmp)
        score = predict.run(tmp, prefix="demo")
    return {"数据安全风险": score*0.7,
            "网络安全风险": score*0.6,
            "技术风险": score*0.5}

gr.Interface(fn=pdf_to_radar,
             inputs=gr.File(label="上传年报 PDF"),
             outputs=gr.Radar(label="数字技术风险雷达"),
             title="Digi-Risk Scanner",
             description="上传年报，30 秒生成企业数字风险雷达图").launch()

